Skip to content

float tests: deduplicate min, max, and rounding tests #142243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 14, 2025

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Jun 9, 2025

Part of #141726

Best reviewed commit-by-commit.

  • Use assert_biteq! in the mod.rs tests. This requires some trickery to make shadowing macros with imports work.
  • The min, max, minimum, maximum tests in tests/floats/f*.rs are entirely subsumed by what we already have in tests/float/mod.rs, so I just removed them.
  • The rounding tests (floor etc) in f*.rs had more test points, so I copied them over. They didn't have 0.5 and -0.5 though which seem like interesting points in particular regarding the sign of the resulting zero if that's what it sounds to, and they didn't max min/max/inf/nan tests, so this was really a merger of both tests.

r? @tgross35

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 9, 2025
assert_biteq!((-0.0 as Float).midpoint(-0.0), -0.0);
assert_biteq!((-5.0 as Float).midpoint(5.0), 0.0);
assert_biteq!(Float::MAX.midpoint(Float::MIN), 0.0);
assert_biteq!(Float::MIN.midpoint(Float::MAX), 0.0);
Copy link
Member Author

@RalfJung RalfJung Jun 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old test seemed to assume that the result of MIN.midpoint(MAX) should be -0.0, but actually we return 0.0.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The midpoint function in C++ with clang and GCC also seems to return +0.0, so this should be fine. We don't guarantee the sign of zero anyway for midpoint.

@RalfJung RalfJung force-pushed the float-test-dedup branch from dc526c1 to 7171984 Compare June 9, 2025 12:18
@RalfJung RalfJung force-pushed the float-test-dedup branch from 7171984 to 1b6bb45 Compare June 9, 2025 12:24
assert_eq!(Float::MAX.ceil(), Float::MAX);
assert_eq!(Float::MIN.ceil(), Float::MIN);
assert_eq!(Float::MIN_POSITIVE.ceil(), 1.0);
assert_eq!((-Float::MIN_POSITIVE).ceil(), 0.0);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bunch of the -Float::MIN_POSITIVE rounding tests were missing the - as well.

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the cleanup. One question then r=me.

@@ -14,10 +37,11 @@ macro_rules! assert_approx_eq {
);
}};
}
pub(crate) use assert_approx_eq_ as assert_approx_eq;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for the trailing _ rather than just pub(crate) use assert_approx_eq;? I assume there may be some name conflicts.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got an error about name clashes:

error[E0659]: `assert_approx_eq` is ambiguous
   --> library/coretests/tests/floats/mod.rs:681:9
    |
681 |         assert_approx_eq!((-1.7 as Float).fract(), -0.7);
    |         ^^^^^^^^^^^^^^^^ ambiguous name
    |
    = note: ambiguous because of a conflict between a `macro_rules` name and a non-`macro_rules` name from another module

I think I'll pick actually proper names for both runtime and const macros and use imports for name management, that's probably clearer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I restructured the macros a bit to make it more clear (I think), please take a look. Putting the const ones in a module doesn't work out that well since (a) macros have their own special global namespace, and (b) we can't glob-import them anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that looks good to me. Maybe just add a breadcrumb comment at the use {assert_*_const as assert_*} remapping? Also if you don't mind grabbing it while you're here, I notice the preexisting doc example for the float_test macro is missing its closing /// ``` .

I still can't wrap my head around the way macro namespaces work sometimes...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already a comment there. What would you like to have added to it?

I still can't wrap my head around the way macro namespaces work sometimes...

Yeah.^^ I wonder if we can get rid of it in a future edition...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a comment at the assert_approx_eq_rt as assert_approx_eq version mentioning that the rt version is used by default so const can shadow it, I was just thinking to mirror this at the place we shadow it (lines 193-194). But it's noncritical, r=me with or without it.

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops forgot the ✅

@RalfJung RalfJung force-pushed the float-test-dedup branch 2 times, most recently from a2584a4 to 6da4f58 Compare June 13, 2025 07:06
@RalfJung
Copy link
Member Author

@bors r=tgross35

@bors
Copy link
Collaborator

bors commented Jun 13, 2025

📌 Commit 25ec235 has been approved by tgross35

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 13, 2025
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 14, 2025
float tests: deduplicate min, max, and rounding tests

Part of rust-lang#141726

Best reviewed commit-by-commit.

- Use `assert_biteq!` in the `mod.rs` tests. This requires some trickery to make shadowing macros with imports work.
- The min, max, minimum, maximum tests in `tests/floats/f*.rs` are entirely subsumed by what we already have in `tests/float/mod.rs`, so I just removed them.
- The rounding tests (floor etc) in `f*.rs` had more test points, so I copied them over. They didn't have `0.5` and `-0.5` though which seem like interesting points in particular regarding the sign of the resulting zero if that's what it sounds to, and they didn't max min/max/inf/nan tests, so this was really a merger of both tests.

r? `@tgross35`
bors added a commit that referenced this pull request Jun 14, 2025
Rollup of 9 pull requests

Successful merges:

 - #140593 (Temporary lifetime extension through tuple struct and tuple variant constructors)
 - #141399 ([rustdoc] Give more information into extracted doctest information)
 - #141493 (Delegate `<SocketAddr as Debug>` to `ByteStr`)
 - #141811 (Unimplement unsized_locals)
 - #142243 (float tests: deduplicate min, max, and rounding tests)
 - #142464 (variadic functions: remove list of supported ABIs from error)
 - #142477 (Fix incorrect suggestion when calling an associated type with a type anchor)
 - #142484 (Remove unneeded lifetime bound from signature of BTreeSet::extract_if)
 - #142489 (Update the `compiler-builtins` subtree)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 4cf4473 into rust-lang:master Jun 14, 2025
10 checks passed
@rustbot rustbot added this to the 1.89.0 milestone Jun 14, 2025
rust-timer added a commit that referenced this pull request Jun 14, 2025
Rollup merge of #142243 - RalfJung:float-test-dedup, r=tgross35

float tests: deduplicate min, max, and rounding tests

Part of #141726

Best reviewed commit-by-commit.

- Use `assert_biteq!` in the `mod.rs` tests. This requires some trickery to make shadowing macros with imports work.
- The min, max, minimum, maximum tests in `tests/floats/f*.rs` are entirely subsumed by what we already have in `tests/float/mod.rs`, so I just removed them.
- The rounding tests (floor etc) in `f*.rs` had more test points, so I copied them over. They didn't have `0.5` and `-0.5` though which seem like interesting points in particular regarding the sign of the resulting zero if that's what it sounds to, and they didn't max min/max/inf/nan tests, so this was really a merger of both tests.

r? ``@tgross35``
@RalfJung RalfJung deleted the float-test-dedup branch June 14, 2025 12:53
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Jun 15, 2025
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#140593 (Temporary lifetime extension through tuple struct and tuple variant constructors)
 - rust-lang/rust#141399 ([rustdoc] Give more information into extracted doctest information)
 - rust-lang/rust#141493 (Delegate `<SocketAddr as Debug>` to `ByteStr`)
 - rust-lang/rust#141811 (Unimplement unsized_locals)
 - rust-lang/rust#142243 (float tests: deduplicate min, max, and rounding tests)
 - rust-lang/rust#142464 (variadic functions: remove list of supported ABIs from error)
 - rust-lang/rust#142477 (Fix incorrect suggestion when calling an associated type with a type anchor)
 - rust-lang/rust#142484 (Remove unneeded lifetime bound from signature of BTreeSet::extract_if)
 - rust-lang/rust#142489 (Update the `compiler-builtins` subtree)

r? `@ghost`
`@rustbot` modify labels: rollup
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Jun 16, 2025
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#140593 (Temporary lifetime extension through tuple struct and tuple variant constructors)
 - rust-lang/rust#141399 ([rustdoc] Give more information into extracted doctest information)
 - rust-lang/rust#141493 (Delegate `<SocketAddr as Debug>` to `ByteStr`)
 - rust-lang/rust#141811 (Unimplement unsized_locals)
 - rust-lang/rust#142243 (float tests: deduplicate min, max, and rounding tests)
 - rust-lang/rust#142464 (variadic functions: remove list of supported ABIs from error)
 - rust-lang/rust#142477 (Fix incorrect suggestion when calling an associated type with a type anchor)
 - rust-lang/rust#142484 (Remove unneeded lifetime bound from signature of BTreeSet::extract_if)
 - rust-lang/rust#142489 (Update the `compiler-builtins` subtree)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants